package com.sugon.quartz.listener;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;

import lombok.extern.slf4j.Slf4j;

/**
 * @desc:
 * @author: luoy
 * @date: 2021-12-09 17:52
 */
@Slf4j
public class MyJobListener implements JobListener {
    @Override
    public String getName() {
        return "listen1";
    }

    /**
     * scheduler在JobDetail将要被执行时调用这个方法【JobDetail执行前】
     * @see #jobExecutionVetoed(JobExecutionContext)
     */
    @Override
    public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {

        String name = jobExecutionContext.getJobDetail().getJobClass().getName();
        log.info("当前Job的名称为：" + name + "，JobDetail将要被执行了...");
    }

    /**
     * scheduler在JobDetail即将被执行，但又被TriggerListener否决时会调用该方法
     * @see #jobToBeExecuted(JobExecutionContext)
     */
    @Override
    public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {

        String name = jobExecutionContext.getJobDetail().getJobClass().getName();
        log.info("当前Job的名称为：" + name + "，JobDetail将要被执，但被TriggerListener否决...");

    }


    /**
     * scheduler在JobDetail被执行后调用这个方法
     */
    @Override
    public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException e) {

        String name = jobExecutionContext.getJobDetail().getJobClass().getName();
        log.info("当前Job的名称为：" + name + "，JobDetail执行完成了...");

    }
}
